package com.dq.service.org.impl;

import com.dq.controller.in.StaffUserServiceProjectCentreQuery;
import com.dq.domain.service.centre.StaffUserServiceProjectCentre;
import com.dq.exception.customException.AdminException;
import com.dq.repository.BaseRepositories;
import com.dq.service.org.StaffUserServiceProjectCentreService;
import com.dq.service.sys.user.WxUserService;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author luchangtong
 * @Date 2020/4/3 10:58
 */
@Service
public class StaffUserServiceProjectCentreServiceImpl extends BaseRepositories implements StaffUserServiceProjectCentreService {
    @Autowired
    private WxUserService wxUserService;
    @Override
    public Vo list(StaffUserServiceProjectCentreQuery staffUserServiceProjectCentreQuery) throws AdminException {
        staffUserServiceProjectCentreQuery.format();
        Map<String, Object> query = staffUserServiceProjectCentreQuery.parseMap();
        if(staffUserServiceProjectCentreQuery.getServiceProjectId() != null){
            query.put("serviceProject_id",staffUserServiceProjectCentreQuery.getServiceProjectId());
            query.remove("serviceProjectId");
        }
        if(staffUserServiceProjectCentreQuery.getStaffUserId() != null){
            query.put("staffUser_id",staffUserServiceProjectCentreQuery.getStaffUserId());
            query.remove("staffUserId");
        }
        if(staffUserServiceProjectCentreQuery.getOrgId() != null){
            query.put("staffUser_section_id",staffUserServiceProjectCentreQuery.getOrgId());
            query.remove("orgId");
        }
        List<StaffUserServiceProjectCentre> list = dao.find(dao.query2Hql(StaffUserServiceProjectCentre.class, query), query);
        List<StaffUserServiceProjectCentre.Vo> voList = new ArrayList<>();
        list.forEach(staffUserServiceProjectCentre -> {
            StaffUserServiceProjectCentre.Vo vo = (StaffUserServiceProjectCentre.Vo) staffUserServiceProjectCentre.toVO();
            vo.setLableStrList(wxUserService.getWxUserLable(staffUserServiceProjectCentre.getStaffUser()));
            voList.add(vo);
        });
        Long count = dao.count(dao.count2Hql(StaffUserServiceProjectCentre.class, query), query);
        return new ListDataVo(voList,count);
    }
}
